<?php require_once('../Connections/webtintuc.php'); ?>
<?php
// Load the common classes
require_once('../includes/common/KT_common.php');

// Load the tNG classes
require_once('../includes/tng/tNG.inc.php');

// Load the required classes
require_once('../includes/tfi/TFI.php');
require_once('../includes/tso/TSO.php');
require_once('../includes/nav/NAV.php');

// Make unified connection variable
$conn_webtintuc = new KT_connection($webtintuc, $database_webtintuc);

//Start Restrict Access To Page
$restrict = new tNG_RestrictAccess($conn_webtintuc, "../");
//Grand Levels: Level
$restrict->addLevel("1");
$restrict->Execute();
//End Restrict Access To Page

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

// Filter
$tfi_listtin1 = new TFI_TableFilter($conn_webtintuc, "tfi_listtin1");
$tfi_listtin1->addColumn("tin.TieuDe", "STRING_TYPE", "TieuDe", "%");
$tfi_listtin1->addColumn("tin.urlHinh", "STRING_TYPE", "urlHinh", "%");
$tfi_listtin1->addColumn("theloai.idTL", "NUMERIC_TYPE", "idTL", "=");
$tfi_listtin1->addColumn("loaitin.idLT", "NUMERIC_TYPE", "idLT", "=");
$tfi_listtin1->addColumn("sukien.idSK", "NUMERIC_TYPE", "idSK", "=");
$tfi_listtin1->addColumn("tin.Ngay", "DATE_TYPE", "Ngay", "=");
$tfi_listtin1->addColumn("tin.AnHien", "NUMERIC_TYPE", "AnHien", "=");
$tfi_listtin1->Execute();

// Sorter
$tso_listtin1 = new TSO_TableSorter("rstin1", "tso_listtin1");
$tso_listtin1->addColumn("tin.TieuDe");
$tso_listtin1->addColumn("tin.urlHinh");
$tso_listtin1->addColumn("theloai.TenTL");
$tso_listtin1->addColumn("loaitin.Ten");
$tso_listtin1->addColumn("sukien.MoTa");
$tso_listtin1->addColumn("tin.Ngay");
$tso_listtin1->addColumn("tin.AnHien");
$tso_listtin1->setDefault("tin.TieuDe");
$tso_listtin1->Execute();

// Navigation
$nav_listtin1 = new NAV_Regular("nav_listtin1", "rstin1", "../", $_SERVER['PHP_SELF'], 10);

mysql_select_db($database_webtintuc, $webtintuc);
$query_Recordset1 = "SELECT TenTL, idTL FROM theloai ORDER BY TenTL";
$Recordset1 = mysql_query($query_Recordset1, $webtintuc) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

mysql_select_db($database_webtintuc, $webtintuc);
$query_Recordset2 = "SELECT Ten, idLT FROM loaitin ORDER BY Ten";
$Recordset2 = mysql_query($query_Recordset2, $webtintuc) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);

mysql_select_db($database_webtintuc, $webtintuc);
$query_Recordset3 = "SELECT MoTa, idSK FROM sukien ORDER BY MoTa";
$Recordset3 = mysql_query($query_Recordset3, $webtintuc) or die(mysql_error());
$row_Recordset3 = mysql_fetch_assoc($Recordset3);
$totalRows_Recordset3 = mysql_num_rows($Recordset3);

//NeXTenesio3 Special List Recordset
$maxRows_rstin1 = $_SESSION['max_rows_nav_listtin1'];
$pageNum_rstin1 = 0;
if (isset($_GET['pageNum_rstin1'])) {
  $pageNum_rstin1 = $_GET['pageNum_rstin1'];
}
$startRow_rstin1 = $pageNum_rstin1 * $maxRows_rstin1;

// Defining List Recordset variable
$NXTFilter_rstin1 = "1=1";
if (isset($_SESSION['filter_tfi_listtin1'])) {
  $NXTFilter_rstin1 = $_SESSION['filter_tfi_listtin1'];
}
// Defining List Recordset variable
$NXTSort_rstin1 = "tin.TieuDe";
if (isset($_SESSION['sorter_tso_listtin1'])) {
  $NXTSort_rstin1 = $_SESSION['sorter_tso_listtin1'];
}
mysql_select_db($database_webtintuc, $webtintuc);

$query_rstin1 = "SELECT tin.TieuDe, tin.urlHinh, theloai.TenTL AS idTL, loaitin.Ten AS idLT, sukien.MoTa AS idSK, tin.Ngay, tin.AnHien, tin.idTin FROM ((tin LEFT JOIN theloai ON tin.idTL = theloai.idTL) LEFT JOIN loaitin ON tin.idLT = loaitin.idLT) LEFT JOIN sukien ON tin.idSK = sukien.idSK WHERE {$NXTFilter_rstin1} ORDER BY {$NXTSort_rstin1}";
$query_limit_rstin1 = sprintf("%s LIMIT %d, %d", $query_rstin1, $startRow_rstin1, $maxRows_rstin1);
$rstin1 = mysql_query($query_limit_rstin1, $webtintuc) or die(mysql_error());
$row_rstin1 = mysql_fetch_assoc($rstin1);

if (isset($_GET['totalRows_rstin1'])) {
  $totalRows_rstin1 = $_GET['totalRows_rstin1'];
} else {
  $all_rstin1 = mysql_query($query_rstin1);
  $totalRows_rstin1 = mysql_num_rows($all_rstin1);
}
$totalPages_rstin1 = ceil($totalRows_rstin1/$maxRows_rstin1)-1;
//End NeXTenesio3 Special List Recordset

$nav_listtin1->checkBoundries();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="main.css" rel="stylesheet" type="text/css" /><link href="../includes/skins/mxkollection3.css" rel="stylesheet" type="text/css" media="all" /><script src="../includes/common/js/base.js" type="text/javascript"></script><script src="../includes/common/js/utility.js" type="text/javascript"></script><script src="../includes/skins/style.js" type="text/javascript"></script><script src="../includes/nxt/scripts/list.js" type="text/javascript"></script><script src="../includes/nxt/scripts/list.js.php" type="text/javascript"></script><script type="text/javascript">
$NXT_LIST_SETTINGS = {
  duplicate_buttons: true,
  duplicate_navigation: true,
  row_effects: true,
  show_as_buttons: true,
  record_counter: true
}
</script><style type="text/css">
  /* Dynamic List row settings */
  .KT_col_TieuDe {width:140px; overflow:hidden;}
  .KT_col_urlHinh {width:140px; overflow:hidden;}
  .KT_col_idTL {
	width:60px;
	overflow:hidden;
}
  .KT_col_idLT {
	width:60px;
	overflow:hidden;
}
  .KT_col_idSK {
	width:60px;
	overflow:hidden;
}
  .KT_col_Ngay {
	width:60px;
	overflow:hidden;
}
  .KT_col_AnHien {
	width:60px;
	overflow:hidden;
}
</style>

</head>

<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td id="banner" colspan="2">TIN TỨC ONLINE. TRANG QUẢN TRỊ</td>
  </tr>
  <tr>
    <td width="150" valign="top" id="left"><table id="menu" width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><a href="index.php">Trang chủ</a></td>
      </tr>
      <tr>
        <td><a href="listTheLoai.php"> thể loại</a></td>
      </tr>
      <tr>
        <td><a href="listLoaiTin.php"> loại tin</a></td>
      </tr>
      <tr>
        <td><a href="listTin.php"> Tin</a><a href="listUsers.php">Users</a></td>
      </tr>
      <tr>
        <td><a href="../index.php"> Thoát</a></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
      </tr>
    </table></td>
    <td valign="top" id="right">&nbsp;
<div class="KT_tng" id="listtin1">
  <h1> Tin
    <?php
  $nav_listtin1->Prepare();
  require("../includes/nav/NAV_Text_Statistics.inc.php");
?>
  </h1>
  <div class="KT_tnglist">
    <form action="<?php echo KT_escapeAttribute(KT_getFullUri()); ?>" method="post" id="form1">
      <div class="KT_options"> <a href="<?php echo $nav_listtin1->getShowAllLink(); ?>"><?php echo NXT_getResource("Show"); ?>
            <?php 
  // Show IF Conditional region1
  if (@$_GET['show_all_nav_listtin1'] == 1) {
?>
            <?php echo $_SESSION['default_max_rows_nav_listtin1']; ?>
            <?php 
  // else Conditional region1
  } else { ?>
            <?php echo NXT_getResource("all"); ?>
            <?php } 
  // endif Conditional region1
?>
            <?php echo NXT_getResource("records"); ?></a> &nbsp;
        &nbsp;
                            <?php 
  // Show IF Conditional region2
  if (@$_SESSION['has_filter_tfi_listtin1'] == 1) {
?>
                            <a href="<?php echo $tfi_listtin1->getResetFilterLink(); ?>"><?php echo NXT_getResource("Reset filter"); ?></a>
                            <?php 
  // else Conditional region2
  } else { ?>
                            <a href="<?php echo $tfi_listtin1->getShowFilterLink(); ?>"><?php echo NXT_getResource("Show filter"); ?></a>
                            <?php } 
  // endif Conditional region2
?>
      </div>
      <table cellpadding="2" cellspacing="0" class="KT_tngtable">
        <thead>
          <tr class="KT_row_order">
            <th> <input type="checkbox" name="KT_selAll" id="KT_selAll"/>            </th>
            <th id="TieuDe" class="KT_sorter KT_col_TieuDe <?php echo $tso_listtin1->getSortIcon('tin.TieuDe'); ?>"> <a href="<?php echo $tso_listtin1->getSortLink('tin.TieuDe'); ?>">TieuDe</a> </th>
            <th id="urlHinh" class="KT_sorter KT_col_urlHinh <?php echo $tso_listtin1->getSortIcon('tin.urlHinh'); ?>"> <a href="<?php echo $tso_listtin1->getSortLink('tin.urlHinh'); ?>">urlHinh</a> </th>
            <th id="idTL" class="KT_sorter KT_col_idTL <?php echo $tso_listtin1->getSortIcon('theloai.TenTL'); ?>"> <a href="<?php echo $tso_listtin1->getSortLink('theloai.TenTL'); ?>">idTL</a> </th>
            <th id="idLT" class="KT_sorter KT_col_idLT <?php echo $tso_listtin1->getSortIcon('loaitin.Ten'); ?>"> <a href="<?php echo $tso_listtin1->getSortLink('loaitin.Ten'); ?>">idLT</a> </th>
            <th id="idSK" class="KT_sorter KT_col_idSK <?php echo $tso_listtin1->getSortIcon('sukien.MoTa'); ?>"> <a href="<?php echo $tso_listtin1->getSortLink('sukien.MoTa'); ?>">idSK</a> </th>
            <th id="Ngay" class="KT_sorter KT_col_Ngay <?php echo $tso_listtin1->getSortIcon('tin.Ngay'); ?>"> <a href="<?php echo $tso_listtin1->getSortLink('tin.Ngay'); ?>">Ngay</a> </th>
            <th id="AnHien" class="KT_sorter KT_col_AnHien <?php echo $tso_listtin1->getSortIcon('tin.AnHien'); ?>"> <a href="<?php echo $tso_listtin1->getSortLink('tin.AnHien'); ?>">AnHien</a> </th>
            <th>&nbsp;</th>
          </tr>
          <?php 
  // Show IF Conditional region3
  if (@$_SESSION['has_filter_tfi_listtin1'] == 1) {
?>
          <tr class="KT_row_filter">
            <td>&nbsp;</td>
            <td><input type="text" name="tfi_listtin1_TieuDe" id="tfi_listtin1_TieuDe" value="<?php echo KT_escapeAttribute(@$_SESSION['tfi_listtin1_TieuDe']); ?>" size="20" maxlength="255" /></td>
            <td><input type="text" name="tfi_listtin1_urlHinh" id="tfi_listtin1_urlHinh" value="<?php echo KT_escapeAttribute(@$_SESSION['tfi_listtin1_urlHinh']); ?>" size="20" maxlength="255" /></td>
            <td><select name="tfi_listtin1_idTL" id="tfi_listtin1_idTL">
              <option value="" <?php if (!(strcmp("", @$_SESSION['tfi_listtin1_idTL']))) {echo "SELECTED";} ?>><?php echo NXT_getResource("None"); ?></option>
              <?php
do {  
?>
              <option value="<?php echo $row_Recordset1['idTL']?>"<?php if (!(strcmp($row_Recordset1['idTL'], @$_SESSION['tfi_listtin1_idTL']))) {echo "SELECTED";} ?>><?php echo $row_Recordset1['TenTL']?></option>
              <?php
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
  $rows = mysql_num_rows($Recordset1);
  if($rows > 0) {
      mysql_data_seek($Recordset1, 0);
	  $row_Recordset1 = mysql_fetch_assoc($Recordset1);
  }
?>
            </select>            </td>
            <td><select name="tfi_listtin1_idLT" id="tfi_listtin1_idLT">
              <option value="" <?php if (!(strcmp("", @$_SESSION['tfi_listtin1_idLT']))) {echo "SELECTED";} ?>><?php echo NXT_getResource("None"); ?></option>
              <?php
do {  
?>
              <option value="<?php echo $row_Recordset2['idLT']?>"<?php if (!(strcmp($row_Recordset2['idLT'], @$_SESSION['tfi_listtin1_idLT']))) {echo "SELECTED";} ?>><?php echo $row_Recordset2['Ten']?></option>
              <?php
} while ($row_Recordset2 = mysql_fetch_assoc($Recordset2));
  $rows = mysql_num_rows($Recordset2);
  if($rows > 0) {
      mysql_data_seek($Recordset2, 0);
	  $row_Recordset2 = mysql_fetch_assoc($Recordset2);
  }
?>
            </select>            </td>
            <td><select name="tfi_listtin1_idSK" id="tfi_listtin1_idSK">
              <option value="" <?php if (!(strcmp("", @$_SESSION['tfi_listtin1_idSK']))) {echo "SELECTED";} ?>><?php echo NXT_getResource("None"); ?></option>
              <?php
do {  
?>
              <option value="<?php echo $row_Recordset3['idSK']?>"<?php if (!(strcmp($row_Recordset3['idSK'], @$_SESSION['tfi_listtin1_idSK']))) {echo "SELECTED";} ?>><?php echo $row_Recordset3['MoTa']?></option>
              <?php
} while ($row_Recordset3 = mysql_fetch_assoc($Recordset3));
  $rows = mysql_num_rows($Recordset3);
  if($rows > 0) {
      mysql_data_seek($Recordset3, 0);
	  $row_Recordset3 = mysql_fetch_assoc($Recordset3);
  }
?>
            </select>            </td>
            <td><input type="text" name="tfi_listtin1_Ngay" id="tfi_listtin1_Ngay" value="<?php echo @$_SESSION['tfi_listtin1_Ngay']; ?>" size="10" maxlength="22" /></td>
            <td><input type="text" name="tfi_listtin1_AnHien" id="tfi_listtin1_AnHien" value="<?php echo KT_escapeAttribute(@$_SESSION['tfi_listtin1_AnHien']); ?>" size="20" maxlength="100" /></td>
            <td><input type="submit" name="tfi_listtin1" value="<?php echo NXT_getResource("Filter"); ?>" /></td>
          </tr>
          <?php } 
  // endif Conditional region3
?>
        </thead>
        <tbody>
          <?php if ($totalRows_rstin1 == 0) { // Show if recordset empty ?>
          <tr>
            <td colspan="9"><?php echo NXT_getResource("The table is empty or the filter you've selected is too restrictive."); ?></td>
          </tr>
          <?php } // Show if recordset empty ?>
          <?php if ($totalRows_rstin1 > 0) { // Show if recordset not empty ?>
          <?php do { ?>
          <tr class="<?php echo @$cnt1++%2==0 ? "" : "KT_even"; ?>">
            <td><input type="checkbox" name="kt_pk_tin" class="id_checkbox" value="<?php echo $row_rstin1['idTin']; ?>" />
                <input type="hidden" name="idTin" class="id_field" value="<?php echo $row_rstin1['idTin']; ?>" />            </td>
            <td><div class="KT_col_TieuDe"><?php echo KT_FormatForList($row_rstin1['TieuDe'], 40); ?></div></td>
            <td><div class="KT_col_urlHinh"><?php echo KT_FormatForList($row_rstin1['urlHinh'], 20); ?></div></td>
            <td><div class="KT_col_idTL"><?php echo KT_FormatForList($row_rstin1['idTL'], 20); ?></div></td>
            <td><div class="KT_col_idLT"><?php echo KT_FormatForList($row_rstin1['idLT'], 20); ?></div></td>
            <td><div class="KT_col_idSK"><?php echo KT_FormatForList($row_rstin1['idSK'], 20); ?></div></td>
            <td><div class="KT_col_Ngay"><?php echo KT_formatDate($row_rstin1['Ngay']); ?></div></td>
            <td><div class="KT_col_AnHien"><?php echo KT_FormatForList($row_rstin1['AnHien'], 20); ?></div></td>
            <td><a class="KT_edit_link" href="formTin.php?idTin=<?php echo $row_rstin1['idTin']; ?>&amp;KT_back=1"><?php echo NXT_getResource("edit_one"); ?></a> <a class="KT_delete_link" href="#delete"><?php echo NXT_getResource("delete_one"); ?></a> </td>
          </tr>
          <?php } while ($row_rstin1 = mysql_fetch_assoc($rstin1)); ?>
          <?php } // Show if recordset not empty ?>
        </tbody>
      </table>
      <div class="KT_bottomnav">
        <div>
          <?php
            $nav_listtin1->Prepare();
            require("../includes/nav/NAV_Text_Navigation.inc.php");
          ?>
        </div>
      </div>
      <div class="KT_bottombuttons">
        <div class="KT_operations"> <a class="KT_edit_op_link" href="#" onclick="nxt_list_edit_link_form(this); return false;"><?php echo NXT_getResource("edit_all"); ?></a> <a class="KT_delete_op_link" href="#" onclick="nxt_list_delete_link_form(this); return false;"><?php echo NXT_getResource("delete_all"); ?></a> </div>
        <span>&nbsp;</span>
        <select name="no_new" id="no_new">
          <option value="1">1</option>
          <option value="3">3</option>
          <option value="6">6</option>
        </select>
        <a class="KT_additem_op_link" href="formTin.php?KT_back=1" onclick="return nxt_list_additem(this)"><?php echo NXT_getResource("add new"); ?></a> </div>
    </form>
  </div>
  <br class="clearfixplain" />
</div>
<p>&nbsp;</p>
</td>
  </tr>
</table>
</body>
</html>
<?php
mysql_free_result($Recordset1);

mysql_free_result($Recordset2);

mysql_free_result($Recordset3);

mysql_free_result($rstin1);
?>
